﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.ServiceModel.Dispatcher;
using System.Text;
using System.Threading.Tasks;

namespace ebMS3dotnet.Core.Configuration
{
    [ConfigurationCollection(typeof(FilterElement), AddItemName = "filter")]
    public class FilterElementCollection : ConfigurationElementCollection
    {
        public FilterElement this[int index]
        {
            get
            {
                return (FilterElement)base.BaseGet(index);
            }
            set
            {
                if (base.BaseGet(index) != null)
                {
                    base.BaseRemoveAt(index);
                }
                this.BaseAdd(index, value);
            }
        }

        public new FilterElement this[string name]
        {
            get
            {
                return (FilterElement)base.BaseGet(name);
            }
        }


        public FilterElementCollection()
        {
        }


        public void Add(FilterElement element)
        {
            if (!this.IsReadOnly() && element == null)
            {
                throw new ArgumentNullException("element");
            }
            this.BaseAdd(element);
        }

        
        public void Clear()
        {
            base.BaseClear();
        }


        protected override ConfigurationElement CreateNewElement()
        {
            return new FilterElement();
        }

  
        protected override object GetElementKey(ConfigurationElement element)
        {
            return ((FilterElement)element).Name;
        }

      
        protected override bool IsElementRemovable(ConfigurationElement element)
        {
            return true;
        }

 
        public override bool IsReadOnly()
        {
            return false;
        }


        public void Remove(FilterElement element)
        {
            if (!this.IsReadOnly() && element == null)
            {
                throw new ArgumentNullException("element");
            }
            base.BaseRemove(this.GetElementKey(element));
        }

        
    }
}
